package com.buct.coder.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buct.coder.facade.request.PageRequest;
import com.buct.coder.facade.response.ApiResult;
import com.buct.coder.model.Contest;
import com.buct.coder.service.IContestService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 近期比赛信息 前端控制器
 * </p>
 *
 * @author xinzi
 * @since 2022-08-17
 */
@RestController
@RequestMapping("/contest")
public class ContestController {

    @Resource
    private IContestService contestService;


    @PostMapping("/list")
    public ApiResult<Page<Contest>> findPages(@RequestBody PageRequest pageRequest) {
        return ApiResult.success(contestService.page(
                new Page<>(pageRequest.getPage(), pageRequest.getSize())
        ));
    }

    @DeleteMapping("/info/{contestId}")
    public ApiResult<Boolean> deleteContest(@PathVariable("contestId") Long contestId) {
        return ApiResult.success(contestService.removeById(contestId));
    }

    @PutMapping("/info")
    public ApiResult<Boolean> addContest(@RequestBody Contest contest) {
        return ApiResult.success(contestService.save(contest));
    }

    @PatchMapping("/info")
    public ApiResult<Boolean> updateContest(@RequestBody Contest contest) {
        return ApiResult.success(contestService.updateById(contest));
    }

}
